﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using CMS.DAO;
namespace CMS
{
    public class ShopCart
    {

        public ShopCart()
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(ShopCart));
        }

        public static void Add2Cart(int ProductId)
        {
            CMS.DAO.tblProductDAO dao = new tblProductDAO();
            CMS.DAO.tblProductEntity e = dao.SelectOne(ProductId);

            if (System.Web.HttpContext.Current.Session["ArrayListCarts"] == null)
            {
                System.Web.HttpContext.Current.Session["ArrayListCarts"] = new ArrayList();
            }
            ArrayList Arr = (ArrayList)System.Web.HttpContext.Current.Session["ArrayListCarts"];
            for (int iIndex = 0; iIndex < Arr.Count; iIndex++)
            {
                ShopItemCls ShopItemCls = (ShopItemCls)Arr[iIndex];
                if (ShopItemCls.ProductId.Equals(ProductId))
                {
                    ShopItemCls.Quantity++;
                    return;
                }
            }
            ShopItemCls shopItemCls = new ShopItemCls();
            shopItemCls.ProductCode = e.ProductCode;
            shopItemCls.ProductId = ProductId;
            shopItemCls.ProductNameVietnamese = e.ProductName;
            shopItemCls.Quantity = 1;
            shopItemCls.SalePriceVnd = e.RealPrice;
            shopItemCls.UnitName = e.UnitName;
            shopItemCls.Promotion = e.Promotion;
            Arr.Add(shopItemCls);

        }

        public static ShopItemCls[] GetShoppingCarts()
        {
            ArrayList Arr = (ArrayList)System.Web.HttpContext.Current.Session["ArrayListCarts"];
            if (Arr == null) Arr = new ArrayList();
            ShopItemCls[] ShopItems = new ShopItemCls[Arr.Count];
            for (int iIndex = 0; iIndex < ShopItems.Length; iIndex++)
            {
                ShopItems[iIndex] = (ShopItemCls)Arr[iIndex];
            }
            return ShopItems;
        }

        
    }
}


